package data;





import javax.xml.xpath.*;


import javax.xml.namespace.QName;

import javax.xml.parsers.*;

import org.w3c.dom.Document;





@Deprecated public class DBLP {



	private String xmlFile;

    private Document xmlDocument;

    private XPath xPath;

    private String format = "inproceedings";

    

	public DBLP(String xmlFile){

		this.xmlFile = xmlFile;

        initObjects();

	}

	

	

	/* Given an author, return descriptions like: 

	 * author AND year='2001' ANDtitle='test'???

	 * 

	 */

	

	//select all publications' titles involving this author in this year

	public String xpPublicationAY(String author, String year){

		return "//"+format+"[year=\'"+year+"\' and author=\'"+author+"\']/title" ;

	}

	

	//a set of nodes containing this author's publications

	public String xpPublicationA(String author){

		return "//"+format+"[author=\'"+author+"\']/title" ;

	}

	

	public String xpPublicationY(String year){

		return "//"+format+"[year=\'"+year+"\']/title" ;

	}

	

	private void initObjects(){        

        try {

            xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlFile);            

            xPath =  XPathFactory.newInstance().newXPath();

        } catch (Exception ex) {

            ex.printStackTrace();

        }

    }



    public Object read(String expression, QName returnType){

        try {

            XPathExpression xPathExpression = xPath.compile(expression);

            return xPathExpression.evaluate(xmlDocument, returnType);

        } catch (XPathExpressionException ex) {

            ex.printStackTrace();

            return null;

        }

    }



    

    

	

}

